String.prototype.trim = function(){
	return this.replace(/(^\s*)|(\s*$)/g,"");
}

function confirmurl(url,message) {
	url = url+'&pc_hash='+pc_hash;
	if(confirm(message)) redirect(url);
}
function redirect(url) {
	location.href = url;
}

/**
 * 全选checkbox,注意：标识checkbox id固定为为check_box
 * @param string name 列表check名称,如 uid[]
 */
function selectall(name) {
	if ($("#check_box").attr("checked")==false) {
		$("input[name='"+name+"']").each(function() {
			this.checked=false;
		});
	} else {
		$("input[name='"+name+"']").each(function() {
			this.checked=true;
		});
	}
}
function openwinx(url,name,w,h) {
	if(!w) w=screen.width-4;
	if(!h) h=screen.height-95;
	url = url+'&pc_hash='+pc_hash;
    window.open(url,name,"top=100,left=400,width=" + w + ",height=" + h + ",toolbar=no,menubar=no,scrollbars=yes,resizable=yes,location=no,status=no");
}
//弹出对话框
function show_dialog(targetId, targetUrl, targetTitle, targetWidth, targetHeight){
	if(targetUrl.indexOf('?') != -1) {
		targetUrl = targetUrl+'&dailog=1';
	} else {
		targetUrl = targetUrl+'?dailog=1';
	}

	if(!targetWidth) targetWidth=700;
	if(!targetHeight) targetHeight=500;
    window.top.art.dialog(
        {id:targetId, iframe:targetUrl, title:targetTitle, width:targetWidth, height:targetHeight, lock:true},
        function(){
            var d = window.top.art.dialog({id:targetId}).data.iframe;
            var btn = d.document.getElementById('dosubmit');
            btn.click();
            return false;
        },
        function(){
            window.top.art.dialog({id:targetId}).close()
        }
    );
}
/**
 * Tab标签
 * 
 * @param obj  <ul>对象
 * @param name 名称
 */
function tabs(obj, name){
	var cls_show = 'on';
	var cls_hide = '';
    var cnt = $(obj).find("li").size();

	var init = function(idx){
        for(i=1;i<=cnt;i++){
        	//'tab_'+name+'_'+i
            if(idx == i){
                 $('#div_'+name+'_'+i).show();
                 $('#tab_'+name+'_'+i).attr('class',cls_show);
            }else{
                 $('#div_'+name+'_'+i).hide();
                 $('#tab_'+name+'_'+i).attr('class',cls_hide);
            }
        }
	}

    $(obj).find("li").click(function(e){
    	init(this.id.split('_')[2]);
    });

	var hash = window.location.hash;
   	if(hash){
		var tmp = hash.substr(1).split("_");
		if(tmp[0] == name){
	        init(tmp[1]);
		}
	}
	
	$(window).bind('hashchange', function() {
		var hash = window.location.hash;
	   	if(hash){
			var tmp = hash.substr(1).split("_");
			if(tmp[0] == name){
		        init(tmp[1]);
			}
		}
	});
}

//区块搜索
function zone_select(obj, parent_id, select_id){
	parent_id = parseInt(parent_id);
	if(isNaN(parent_id) || parent_id == undefined) {
		parent_id = 0;
	}
	select_id = parseInt(select_id);
	if(isNaN(select_id) || select_id == undefined) {
		select_id = 0;
	}
	$.get(
		'/tools/zoneOption/?pid=' + parent_id + '&zid=' + select_id,
		function(result){
			$(obj).html('<option value="0" selected>请选择...</option>' + result);
		}
	);
}
$(function() {
	if($("#zone_id").size() > 0){
		var zone_id    = $("#zone_id").attr("rel") | 0;
		var subzone_id = $("#subzone_id").attr("rel") | 0;

		zone_select("#zone_id", 0, zone_id);
		if(zone_id >0){
			zone_select("#subzone_id", zone_id, subzone_id);
		}
		$('#zone_id').change(function(){
			if($(this).val() > 0){
				zone_select("#subzone_id", $(this).val());
			}else{
				$("#subzone_id").html('<option value="0" selected>请选择...</option>');
			}
		});
	}
	$(".formtable").find("tr")
		.mouseover(function(){$(this).css({"background":"#F5F5F5"});})
		.mouseout(function(){$(this).css({"background":"#FFFFFF"});})
});

function ResumeError() {
	return true;
}
window.onerror = ResumeError;

